<?php
namespace app\admin\controller;

use app\admin\widget\Name;
use app\common\cache\bank\IBankCache;
use app\common\cache\bank\IBankTypeCache;
use app\common\cache\common\IAreaCache;
use app\common\cache\credit\ICreditCache;
use app\common\cache\credit\ICreditFavoriteCache;
use app\common\cache\credit\ICreditRecommendCache;
use app\common\cache\credit\ICreditTagCache;
use app\common\controller\AdminBaseController;
use app\common\enum\CreditStatus;
use app\common\enum\HtmlEnumValue;
use app\common\enum\IsDelete;
use app\common\ext\IDb;
use app\common\ext\ILog;
use app\common\ext\IRequest;
use think\Db;

class Credit extends AdminBaseController{

    /**
     * @功能：已上架信用卡列表
     * @开发者：cxl
     * @return string
     */
    public function credit_up_list(){
        //接收参数
        $bank_id = IRequest::get('bank_id');
        $credit_product_id = IRequest::get('credit_product_id');
        $credit_bank_code = IRequest::get('credit_bank_code');
        $credit_product_name = IRequest::get('credit_product_name');
        $credit_status = IRequest::get('credit_status');
        $credit_fee = IRequest::get('credit_fee');
        $credit_level = IRequest::get('credit_level');
        $credit_currency = IRequest::get('credit_currency');
        $credit_agency = IRequest::get('credit_agency');
        $credit_privilege = IRequest::get('credit_privilege');
        $credit_purpose = IRequest::get('credit_purpose');
        $credit_color = IRequest::get('credit_color');
        $credit_type = IRequest::get('credit_type');
        $area = IRequest::get("area");

        //整理区域数据
        $province_id = 0;
        $city_id = 0;
        if(!empty($area) && is_array($area)){
            if(!empty($area[0])) $province_id = $area[0];
            if(!empty($area[1])) $city_id = $area[1];
        }

        //判断城市是否正确
        $area_where = null;
        if(!empty($province_id) && !empty($city_id)){
            $area_where = " and ((province is null and city is null) or (province='{$province_id}' and city is null) or (province='{$province_id}' and city ='{$city_id}'))";
        }else{
            if(!empty($province_id)){
                $area_where = " and (province is null or province='{$province_id}')";
            }
        }

        //设置查询条件
        $credit_product_where['cp.is_delete'] = IsDelete::No;
        $credit_product_where['cp.credit_status'] = CreditStatus::release;
        if(!empty($bank_id)) $credit_product_where['cp.bank_id'] = $bank_id;
        if(!empty($credit_product_id)) $credit_product_where['cp.credit_product_id'] = $credit_product_id;
        if(!empty($credit_bank_code)) $credit_product_where['cp.credit_bank_code'] = array("like","%{$credit_bank_code}%");
        if(!empty($credit_product_name)) $credit_product_where['cp.credit_product_name'] = array("like","%{$credit_product_name}%");
        if(!empty($credit_status)) $credit_product_where['cp.credit_status'] = $credit_status;
        if(!empty($credit_fee)) $credit_product_where['cp.credit_fee'] = $credit_fee;
        if(!empty($credit_level)) $credit_product_where['cp.credit_level'] = $credit_level;
        if(!empty($credit_currency)) $credit_product_where[''] =  array("exp","find_in_set({$credit_currency}, cp.credit_currency)");
        if(!empty($credit_agency)) $credit_product_where['cp.credit_agency'] = $credit_agency;
        if(!empty($credit_privilege)) $credit_product_where['cp.credit_privilege'] = $credit_privilege;
        if(!empty($credit_purpose)) $credit_product_where['cp.credit_purpose'] = $credit_purpose;
        if(!empty($credit_color)) $credit_product_where['cp.credit_color'] = $credit_color;
        if(!empty($credit_type)) $credit_product_where['cp.credit_type'] = $credit_type;

        //取得管理员详情
        $credit_list = IDb::getInstance('credit_product as cp')
            ->setDbJoin("credit_product_area as cpa","cp.credit_product_id = cpa.credit_product_id {$area_where}")
            ->setDbWhere($credit_product_where)
            ->setDbOrder("cp.credit_product_id desc")
            ->setDbGroup('cp.credit_product_id')
            ->pag();
        if ($credit_list === false){
            error('获取信用卡列表失败');
        }

        //取得银行数据
        $bank_list = IBankCache::getList();

        //取得城市列表
        $area_list = IAreaCache::getAllList(2);

        //页面赋值
        $this->assign("bank_id",$bank_id);
        $this->assign("credit_product_id",$credit_product_id);
        $this->assign("credit_bank_code",$credit_bank_code);
        $this->assign("credit_product_name",$credit_product_name);
        $this->assign("credit_status",$credit_status);
        $this->assign("credit_fee",$credit_fee);
        $this->assign("credit_level",$credit_level);
        $this->assign("credit_currency",$credit_currency);
        $this->assign("credit_agency",$credit_agency);
        $this->assign("credit_privilege",$credit_privilege);
        $this->assign("credit_purpose",$credit_purpose);
        $this->assign("credit_color",$credit_color);
        $this->assign("credit_type",$credit_type);
        $this->assign("bank_list",$bank_list);
        $this->assign("credit_list",$credit_list);
        $this->assign("area_list",$area_list);
        $this->assign("area",$area);

        //渲染模板输出
        return view("credit_up_list");
    }

    /**
     * @功能：编辑中信用卡列表
     * @开发者：cxl
     * @return string
     */
    public function credit_edit_list(){
        //接收参数
        $bank_id = IRequest::get('bank_id');
        $credit_product_id = IRequest::get('credit_product_id');
        $credit_product_name = IRequest::get('credit_product_name');
        $credit_status = IRequest::get('credit_status');
        $credit_fee = IRequest::get('credit_fee');
        $credit_level = IRequest::get('credit_level');
        $credit_currency = IRequest::get('credit_currency');
        $credit_agency = IRequest::get('credit_agency');
        $credit_privilege = IRequest::get('credit_privilege');
        $credit_purpose = IRequest::get('credit_purpose');
        $credit_color = IRequest::get('credit_color');
        $credit_type = IRequest::get('credit_type');
        $area = IRequest::get("area");

        //整理区域数据
        $province_id = 0;
        $city_id = 0;
        if(!empty($area) && is_array($area)){
            if(!empty($area[0])) $province_id = $area[0];
            if(!empty($area[1])) $city_id = $area[1];
        }

        //判断城市是否正确
        $area_where = null;
        if(!empty($province_id) && !empty($city_id)){
            $area_where = " and ((province is null and city is null) or (province='{$province_id}' and city is null) or (province='{$province_id}' and city ='{$city_id}'))";
        }else{
            if(!empty($province_id)){
                $area_where = " and (province is null or province='{$province_id}')";
            }
        }

        //设置查询条件
        $credit_product_where['cp.is_delete'] = IsDelete::No;
        $credit_product_where['cp.credit_status'] = array("in",array(CreditStatus::edit,CreditStatus::audit,CreditStatus::audit_failure,CreditStatus::down));
        if(!empty($bank_id)) $credit_product_where['cp.bank_id'] = $bank_id;
        if(!empty($credit_product_id)) $credit_product_where['cp.credit_product_id'] = $credit_product_id;
        if(!empty($credit_product_name)) $credit_product_where['cp.credit_product_name'] = array("like","%{$credit_product_name}%");
        if(!empty($credit_status)  && !in_array($credit_status,array(CreditStatus::release)))$credit_product_where['cp.credit_status'] = $credit_status;
        if(!empty($credit_fee)) $credit_product_where['cp.credit_fee'] = $credit_fee;
        if(!empty($credit_level)) $credit_product_where['cp.credit_level'] = $credit_level;
        if(!empty($credit_currency)) $credit_product_where[''] =  array("exp","find_in_set({$credit_currency}, cp.credit_currency)");
        if(!empty($credit_agency)) $credit_product_where['cp.credit_agency'] = $credit_agency;
        if(!empty($credit_privilege)) $credit_product_where['cp.credit_privilege'] = $credit_privilege;
        if(!empty($credit_purpose)) $credit_product_where['cp.credit_purpose'] = $credit_purpose;
        if(!empty($credit_color)) $credit_product_where['cp.credit_color'] = $credit_color;
        if(!empty($credit_type)) $credit_product_where['cp.credit_type'] = $credit_type;

        //取得管理员详情
        $credit_list = IDb::getInstance('credit_product as cp')
            ->setDbWhere($credit_product_where)
            ->setDbJoin("credit_product_area as cpa","cp.credit_product_id = cpa.credit_product_id {$area_where}")
            ->setDbOrder("cp.credit_product_id desc")
            ->setDbGroup('cp.credit_product_id')
            ->pag();

        //取得银行数据
        $bank_list = IBankCache::getList();

        //取得城市列表
        $area_list = IAreaCache::getAllList(2);

        //页面赋值
        $this->assign("bank_id",$bank_id);
        $this->assign("credit_product_id",$credit_product_id);
        $this->assign("credit_product_name",$credit_product_name);
        $this->assign("credit_status",$credit_status);
        $this->assign("credit_fee",$credit_fee);
        $this->assign("credit_level",$credit_level);
        $this->assign("credit_currency",$credit_currency);
        $this->assign("credit_agency",$credit_agency);
        $this->assign("credit_privilege",$credit_privilege);
        $this->assign("credit_purpose",$credit_purpose);
        $this->assign("credit_color",$credit_color);
        $this->assign("credit_type",$credit_type);
        $this->assign("bank_list",$bank_list);
        $this->assign("credit_list",$credit_list);
        $this->assign("area_list",$area_list);
        $this->assign("area",$area);

        //渲染模板输出
        return view("credit_edit_list");
    }

    /**
     * @功能：已删除信用卡列表
     * @开发者：cxl
     * @return string
     */
    public function credit_del_list(){
        //接收参数
        $bank_id = IRequest::get('bank_id');
        $credit_product_id = IRequest::get('credit_product_id');
        $credit_bank_code = IRequest::get('credit_bank_code');
        $credit_product_name = IRequest::get('credit_product_name');
        $credit_status = IRequest::get('credit_status');
        $credit_fee = IRequest::get('credit_fee');
        $credit_level = IRequest::get('credit_level');
        $credit_currency = IRequest::get('credit_currency');
        $credit_agency = IRequest::get('credit_agency');
        $credit_privilege = IRequest::get('credit_privilege');
        $credit_purpose = IRequest::get('credit_purpose');
        $credit_color = IRequest::get('credit_color');
        $credit_type = IRequest::get('credit_type');
        $area = IRequest::get("area");

        //整理区域数据
        $province_id = 0;
        $city_id = 0;
        if(!empty($area) && is_array($area)){
            if(!empty($area[0])) $province_id = $area[0];
            if(!empty($area[1])) $city_id = $area[1];
        }

        //判断城市是否正确
        $area_where = null;
        if(!empty($province_id) && !empty($city_id)){
            $area_where = " and ((province is null and city is null) or (province='{$province_id}' and city is null) or (province='{$province_id}' and city ='{$city_id}'))";
        }else{
            if(!empty($province_id)){
                $area_where = " and (province is null or province='{$province_id}')";
            }
        }

        //设置查询条件
        $credit_product_where['cp.is_delete'] = IsDelete::Yes;
        if(!empty($bank_id)) $credit_product_where['cp.bank_id'] = $bank_id;
        if(!empty($credit_product_id)) $credit_product_where['cp.credit_product_id'] = $credit_product_id;
        if(!empty($credit_bank_code)) $credit_product_where['cp.credit_bank_code'] = array("like","%{$credit_bank_code}%");
        if(!empty($credit_product_name)) $credit_product_where['cp.credit_product_name'] = array("like","%{$credit_product_name}%");
        if(!empty($credit_status)) $credit_product_where['cp.credit_status'] = $credit_status;
        if(!empty($credit_fee)) $credit_product_where['cp.credit_fee'] = $credit_fee;
        if(!empty($credit_level)) $credit_product_where['cp.credit_level'] = $credit_level;
        if(!empty($credit_currency)) $credit_product_where[''] =  array("exp","find_in_set({$credit_currency}, cp.credit_currency)");
        if(!empty($credit_agency)) $credit_product_where['cp.credit_agency'] = $credit_agency;
        if(!empty($credit_privilege)) $credit_product_where['cp.credit_privilege'] = $credit_privilege;
        if(!empty($credit_purpose)) $credit_product_where['cp.credit_purpose'] = $credit_purpose;
        if(!empty($credit_color)) $credit_product_where['cp.credit_color'] = $credit_color;
        if(!empty($credit_type)) $credit_product_where['cp.credit_type'] = $credit_type;

        //取得管理员详情
        $credit_list = IDb::getInstance('credit_product as cp')
            ->setDbWhere($credit_product_where)
            ->setDbJoin("credit_product_area as cpa","cp.credit_product_id = cpa.credit_product_id {$area_where}")
            ->setDbOrder("cp.credit_product_id desc")
            ->setDbGroup('cp.credit_product_id')
            ->pag();

        //取得银行数据
        $bank_list = IBankCache::getList();

        //取得城市列表
        $area_list = IAreaCache::getAllList(2);

        //页面赋值
        $this->assign("bank_id",$bank_id);
        $this->assign("credit_product_id",$credit_product_id);
        $this->assign("credit_bank_code",$credit_bank_code);
        $this->assign("credit_product_name",$credit_product_name);
        $this->assign("credit_status",$credit_status);
        $this->assign("credit_fee",$credit_fee);
        $this->assign("credit_level",$credit_level);
        $this->assign("credit_currency",$credit_currency);
        $this->assign("credit_agency",$credit_agency);
        $this->assign("credit_privilege",$credit_privilege);
        $this->assign("credit_purpose",$credit_purpose);
        $this->assign("credit_color",$credit_color);
        $this->assign("credit_type",$credit_type);
        $this->assign("bank_list",$bank_list);
        $this->assign("credit_list",$credit_list);
        $this->assign("area_list",$area_list);
        $this->assign("area",$area);

        //渲染模板输出
        return view("credit_del_list");
    }

    /**
     * @功能：信用卡详情
     * @开发者：cxl
     * @return string
     */
    public function credit_info(){
        //接收参数
        $credit_product_id = IRequest::get("credit_product_id",IRequest::NOT_EMPTY,"信用卡编号不能为空！");

        //取得信用卡的银行分类列表
        $bank_type_list = IBankTypeCache::getList();

        //取得属性分类列表
        $area_list = IAreaCache::getInfo(2);

        //取得信用卡的银行列表
        $bank_list = IBankCache::getList();

        //取得信用卡信息
        $credit_info = ICreditCache::getInfo($credit_product_id);

        //判断详情数据是否存在
        $product_area_list = array();
        if(!empty($credit_info)){

           if (!empty($credit_info['credit_content_img'])){
               $credit_info['credit_content_img'] = explode(",",$credit_info['credit_content_img']);
           }

            //整理币种
            $credit_info['credit_currency'] = explode(",",$credit_info['credit_currency']);

            //取得所在区域信息
            $credit_product_area = null;
            $credit_product_area['credit_product_id'] = $credit_product_id;
            $credit_product_area['province'] = array("exp","is not null");
            $credit_product_area['city'] = array("exp","is not null");
            $product_area_list = IDb::getInstance('credit_product_area')->setDbFiled("province,city")->setDbWhere($credit_product_area)->sel();
            if($product_area_list === false){
                $product_area_list = array();
            }
        }

        //设置layout
        $this->layout("layout_empty");

        //页面赋值
        $this->assign("credit_product_id",$credit_product_id);
        $this->assign("credit_info",$credit_info);
        $this->assign("area_list",$area_list);
        $this->assign("bank_type_list",$bank_type_list);
        $this->assign("bank_list",$bank_list);
        $this->assign("product_area_list",$product_area_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：信用卡日志
     * @开发者：cxl
     * @return string
     */
    public function credit_log(){
        //接收参数
        $credit_product_id = IRequest::get("credit_product_id",IRequest::NOT_EMPTY,"信用卡编号不能为空！");

        //取得日志
        $credit_product_log_where['credit_product_id'] = $credit_product_id;
        $credit_product_log_list = IDb::getInstance('credit_product_log')->setDbWhere($credit_product_log_where)->setDbOrder("credit_product_log_id desc")->pag();

        //设置layout
        $this->layout("layout_empty");

        //页面赋值
        $this->assign("credit_product_log_list",$credit_product_log_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：提交审核
     * @开发者：cxl
     * @return string
     */
    public function credit_commit(){
        //接收参数
        $credit_product_id = IRequest::get("credit_product_id",IRequest::NOT_EMPTY,"信用卡编号不能为空！");

        //开启事物
        IDb::dbStartTrans();

        //修改管理员信息
        $credit_product_where['credit_product_id'] = $credit_product_id;
        $credit_product_data['credit_status'] = CreditStatus::audit;
        $credit_product_data['update_time'] = get_date_time();
        $credit_upd = IDb::getInstance('credit_product')->setDbWhere($credit_product_where)->setDbData($credit_product_data)->upd();
        if($credit_upd === false){
            //事物回滚
            IDb::dbRollback();

            //提示错误信息
            error("信用卡提交审核失败！");
        }

        //添加操作日志
        $credit_log_add = ILog::CreditLog($credit_product_id,get_login_admin_id(),null,"信用卡提交审核！");
        if ($credit_log_add === false) {
            //事物回滚
            IDb::dbRollback();

            //提示错误信息
            error("信用卡提交审核失败！");
        }

        //提交事物处理
        IDb::dbCommit();

        //删除缓存信息
        ICreditCache::deleteInfo($credit_product_id);
        ICreditCache::deleteList();
        ICreditRecommendCache::deleteList();
        ICreditFavoriteCache::deleteListAll();

        //画面跳转
        $this->success("操作成功！");
    }

    /**
     * @功能：信用卡审核
     * @开发者：cxl
     * @return string
     */
    public function credit_audit(){
        //接收参数
        $credit_product_id = IRequest::get("credit_product_id",IRequest::NOT_EMPTY,"信用卡编号不能为空！");

        //取得信用卡的银行分类列表
        $bank_type_list = IBankTypeCache::getList();

        //取得属性分类列表
        $area_list = IAreaCache::getAllList(2);

        //取得信用卡的银行列表
        $bank_list = IBankCache::getList();

        //取得信用卡信息
        $credit_info = ICreditCache::getInfo($credit_product_id);

        //判断详情数据是否存在
        $product_area_list = array();
        if(!empty($credit_info)){
            //整理币种
            $credit_info['credit_currency'] = explode(",",$credit_info['credit_currency']);

            if (!empty($credit_info['credit_content_img'])){
                $credit_info['credit_content_img'] = explode(",",$credit_info['credit_content_img']);
            }

            //取得所在区域信息
            $credit_product_area_where['credit_product_id'] = $credit_product_id;
            $credit_product_area_where['province'] = array("exp","is not null");
            $credit_product_area_where['city'] = array("exp","is not null");
            $product_area_list = IDb::getInstance('credit_product_area')->setDbFiled("province,city")->setDbWhere($credit_product_area_where)->sel();
            if($product_area_list === false){
                $product_area_list = array();
            }
        }

        //页面赋值
        $this->assign("credit_product_id",$credit_product_id);
        $this->assign("credit_info",$credit_info);
        $this->assign("area_list",$area_list);
        $this->assign("bank_type_list",$bank_type_list);
        $this->assign("bank_list",$bank_list);
        $this->assign("product_area_list",$product_area_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：信用卡审核提交
     * @开发者：cxl
     * @return string
     */
    public function credit_audit_submit(){
        //接收参数
        $credit_product_id = IRequest::get("credit_product_id",IRequest::NOT_EMPTY,"信用卡编号不能为空！");
        $credit_status = IRequest::get("credit_status",IRequest::NOT_EMPTY,"信用卡编号不能为空！");
        $audit_note = IRequest::get("audit_note");

        //开启事物
        IDb::dbStartTrans();

        //修改管理员信息
        $credit_product_where['credit_product_id'] = $credit_product_id;
        $credit_product_data['credit_status'] = $credit_status;
        $credit_product_data['audit_note'] = $audit_note;
        $credit_product_data['update_time'] = get_date_time();
        $credit_upd = IDb::getInstance('credit_product')->setDbWhere($credit_product_where)->setDbData($credit_product_data)->upd();
        if($credit_upd === false){
            //事物回滚
            IDb::dbRollback();

            //提示错误信息
            error("信用卡审核错误！");
        }

        //添加操作日志
        $credit_log_add = ILog::CreditLog($credit_product_id,get_login_admin_id(),null,"信用卡审核！");
        if ($credit_log_add === false) {
            //事物回滚
            IDb::dbRollback();

            //提示错误信息
            error("信用卡审核错误！");
        }

        //提交事物处理
        IDb::dbCommit();

        //删除缓存信息
        ICreditCache::deleteInfo($credit_product_id);
        ICreditCache::deleteList();
        ICreditRecommendCache::deleteList();
        ICreditFavoriteCache::deleteListAll();

        //画面跳转
        $this->success("操作成功！",Url("credit_edit_list"));
    }

    /**
     * @功能：信用卡下架
     * @开发者：cxl
     * @return string
     */
    public function credit_down(){
        //接收参数
        $credit_product_id = IRequest::get("credit_product_id",IRequest::NOT_EMPTY,"信用卡编号不能为空！");

        //开启事物出来
        IDb::dbStartTrans();

        //修改管理员信息
        $credit_product_where['credit_product_id'] = $credit_product_id;
        $credit_product_data['credit_status'] = CreditStatus::down;
        $credit_product_data['update_time'] = get_date_time();
        $credit_upd = IDb::getInstance('credit_product')->setDbWhere($credit_product_where)->setDbData($credit_product_data)->upd();
        if($credit_upd === false){
            //事物回滚
            IDb::dbRollback();

            //错误信息
            error("信用卡下架失败！");
        }

        //修改管理员信息
        $credit_recommend_where['credit_product_id'] = $credit_product_id;
        $credit_recommend_data['is_delete'] = IsDelete::Yes;
        $credit_recommend_data['update_admin'] = get_login_admin_id();
        $credit_recommend_data['update_time'] = get_date_time();
        $credit_recommend_upd = IDb::getInstance('credit_recommend')->setDbWhere($credit_recommend_where)->setDbData($credit_recommend_data)->upd();
        if($credit_recommend_upd === false){
            //事物回滚
            IDb::dbRollback();

            //错误信息
            error("信用卡删除失败！");
        }

        //添加操作日志
        $credit_log_add = ILog::CreditLog($credit_product_id,get_login_admin_id(),null,"信用卡下架！");
        if ($credit_log_add === false) {
            //事物回滚
            IDb::dbRollback();

            //提示错误信息
            error("信用卡下架失败！");
        }

        //事物提交
        IDb::dbCommit();

        //删除缓存信息
        ICreditCache::deleteInfo($credit_product_id);
        ICreditCache::deleteList();
        ICreditRecommendCache::deleteList();
        ICreditFavoriteCache::deleteListAll();

        //画面跳转
        $this->success("操作成功！");
    }

    /**
     * @功能：信用卡删除
     * @开发者：cxl
     * @return string
     */
    public function credit_del(){
        //接收参数
        $credit_product_id = IRequest::get("credit_product_id",IRequest::NOT_EMPTY,"信用卡编号不能为空！");

        //开启事物出来
        IDb::dbStartTrans();

        //修改管理员信息
        $credit_product_where['credit_product_id'] = $credit_product_id;
        $credit_product_data['is_delete'] = IsDelete::Yes;
        $credit_product_data['update_time'] = get_date_time();
        $credit_upd = IDb::getInstance('credit_product')->setDbWhere($credit_product_where)->setDbData($credit_product_data)->upd();
        if($credit_upd === false){
            //事物回滚
            IDb::dbRollback();

            //错误信息
            error("信用卡删除失败！");
        }

        //修改管理员信息
        $credit_recommend_where['credit_product_id'] = $credit_product_id;
        $credit_recommend_data['is_delete'] = IsDelete::Yes;
        $credit_recommend_data['update_admin'] = get_login_admin_id();
        $credit_recommend_data['update_time'] = get_date_time();
        $credit_recommend_upd = IDb::getInstance('credit_recommend')->setDbWhere($credit_recommend_where)->setDbData($credit_recommend_data)->upd();
        if($credit_recommend_upd === false){
            //事物回滚
            IDb::dbRollback();

            //错误信息
            error("信用卡推荐删除失败！");
        }

        //添加操作日志
        $credit_log_add = ILog::CreditLog($credit_product_id,get_login_admin_id(),null,"信用卡删除！");
        if ($credit_log_add === false) {
            //事物回滚
            IDb::dbRollback();

            //提示错误信息
            error("信用卡删除失败！");
        }

        //事物提交
        IDb::dbCommit();

        //删除缓存信息
        ICreditCache::deleteInfo($credit_product_id);
        ICreditCache::deleteList();
        ICreditRecommendCache::deleteList();
        ICreditFavoriteCache::deleteListAll();

        //画面跳转
        $this->success("操作成功！");
    }

    /**
     * @功能：信用卡还原
     * @开发者：cxl
     * @return string
     */
    public function credit_recycle(){
        //接收参数
        $credit_product_id = IRequest::get("credit_product_id",IRequest::NOT_EMPTY,"信用卡编号不能为空！");

        //开启事物出来
        IDb::dbStartTrans();

        //修改管理员信息
        $credit_product_where['credit_product_id'] = $credit_product_id;
        $credit_product_data['is_delete'] = IsDelete::No;
        $credit_product_data['update_time'] = get_date_time();
        $credit_upd = IDb::getInstance('credit_product')->setDbWhere($credit_product_where)->setDbData($credit_product_data)->upd();
        if($credit_upd === false){
            //事物回滚
            IDb::dbRollback();

            //提示错误信息
            error("信用卡还原失败！");
        }

        //添加操作日志
        $credit_log_add = ILog::CreditLog($credit_product_id,get_login_admin_id(),null,"信用卡还原！");
        if ($credit_log_add === false) {
            //事物回滚
            IDb::dbRollback();

            //提示错误信息
            error("信用卡还原失败！");
        }

        //事物提交
        IDb::dbCommit();

        //删除缓存信息
        ICreditCache::deleteInfo($credit_product_id);
        ICreditCache::deleteList();
        ICreditRecommendCache::deleteList();
        ICreditFavoriteCache::deleteListAll();

        //画面跳转
        $this->success("操作成功！");
    }

    /**
     * @功能：信用卡推荐
     * @开发者：cxl
     * @return string
     */
    public function credit_recommend(){
        //接收参数
        $credit_product_id = IRequest::get("credit_product_id",IRequest::NOT_EMPTY,"信用卡编号不能为空！");

        //页面赋值
        $this->assign("credit_product_id",$credit_product_id);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：信用卡推荐
     * @开发者：cxl
     * @return string
     */
    public function credit_recommend_submit(){
        //接收参数
        $credit_product_id = IRequest::get("credit_product_id",IRequest::NOT_EMPTY,"信用卡编号不能为空！");
        $credit_recommend_id = IRequest::get("credit_recommend_id",IRequest::NOT_EMPTY,"信用卡推荐位置编号不能为空！");
        $credit_note = IRequest::get("credit_note");
        $order_by = IRequest::get("order_by");
        $remark = IRequest::get("remark");

        //查看是否存在历史数据
        $credit_recommend_where = null;
        $credit_recommend_where['credit_product_id'] = $credit_product_id;
        $credit_recommend_where['credit_recommend_location'] = $credit_recommend_id;
        $credit_tag_count = IDb::getInstance('credit_recommend')->setDbWhere($credit_recommend_where)->con();
        if($credit_tag_count > 0){
            //修改数据
            $credit_recommend_data = null;
            $credit_recommend_data['credit_note'] = $credit_note;
            $credit_recommend_data['order_by'] = $order_by;
            $credit_recommend_data['remark'] = $remark;
            $credit_recommend_data['is_delete'] = IsDelete::No;
            $credit_recommend_data['update_admin'] = get_login_admin_id();
            $credit_recommend_data['update_time'] = get_date_time();
            $credit_recommend_upd = IDb::getInstance('credit_recommend')->setDbWhere($credit_recommend_where)->setDbData($credit_recommend_data)->upd();
            if($credit_recommend_upd == false){
                error("推荐失败！");
            }
        }else{
            //修改数据
            $credit_recommend_data = null;
            $credit_recommend_data['credit_product_id'] = $credit_product_id;
            $credit_recommend_data['credit_recommend_location'] = $credit_recommend_id;
            $credit_recommend_data['credit_note'] = $credit_note;
            $credit_recommend_data['order_by'] = $order_by;
            $credit_recommend_data['remark'] = $remark;
            $credit_recommend_data['is_delete'] = IsDelete::No;
            $credit_recommend_data['create_admin'] = get_login_admin_id();
            $credit_recommend_data['create_time'] = get_date_time();
            $credit_recommend_add = IDb::getInstance('credit_recommend')->setDbWhere($credit_recommend_where)->setDbData($credit_recommend_data)->add();
            if($credit_recommend_add == false){
                error("推荐失败！");
            }
        }

        //删除缓存信息
        ICreditRecommendCache::deleteList();

        //画面跳转
        $this->success("操作成功！",Url("credit_up_list"));
    }

    /**
     * @功能：信用卡分享记录
     * @开发者：cxl
     * @return string
     */
    public function credit_share_log(){
        //接收参数
        $user_id = IRequest::get("user_id");
        $credit_product_id = IRequest::get("credit_product_id");

        //取得数据
        $credit_share_where = null;
        if(!empty($user_id)) $credit_share_where['user_id'] = $user_id;
        if(!empty($credit_product_id)) $credit_share_where['credit_product_id'] = $credit_product_id;
        $credit_share_list = IDb::getInstance("credit_share")
            ->setDbWhere($credit_share_where)
            ->setDbOrder('share_id desc')
            ->pag();

        //页面赋值
        $this->assign("user_id",$user_id);
        $this->assign("credit_product_id",$credit_product_id);
        $this->assign("credit_share_list",$credit_share_list);

        //渲染模板输出
        return view();
    }
}
